class_name AutoPickableItem
extends PickableItem


@export var pickup_range: float = 100
@export var fly_speed: float = 200
@export var fly_speed_curve: Curve

# @onready var _player: Player = get_tree().get_first_node_in_group("player")
# @onready var _player: Player = Global.get_player()



func _process(delta: float) -> void:
    var d_s := global_position.distance_squared_to(Global.get_player().center_position())
    
    if d_s > pickup_range ** 2: return
    
    # 拾取
    if 4 ** 2 >= d_s:
        pickup()
        ObjectPool.release_obj(self)
        return
    
    var s: float = 1.0
    if fly_speed_curve:
        s = fly_speed_curve.sample(1 - d_s / pickup_range ** 2)
    global_position += fly_speed * s * delta * global_position.direction_to(Global.get_player().center_position())
    
